/*
 * Copyright (C) 拾光分享网 
 * All rights reserved, Designed By www.hiai.top.
 * Email：goodsking@163.com.
 * Version：V1.0.2(20230701).
 */
package top.hiai.my.information;

import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import top.hiai.common.model.Information;

/**
 * @Author www.hiai.top
 * @Email goodsking@163.com
 * @Message 更多资源尽在www.hiai.top
 * @Introduction 类的介绍
 */

public class InformationService {

    private Information informationDao = new Information().dao();

    /**
     * 获取用户的消息
     */
    public Page<Information> getUserMsgList(int pageNum, int pageSize, int uid, int type) {

        String select = " select nid,uid,title,content,createAt,type,is_see ";
        String from = "";
        if (type == 1) {
            from = " from bbs_information where uid=? and type=? or all_user=1 order by createAt desc ";
        } else if (type == 2) {
            from = " from bbs_information where uid=? and type=?  order by createAt desc ";
        }
        Page<Information> articlePage = informationDao.paginate(pageNum, pageSize, select, from, uid, type);
        return articlePage;
    }

    /**
     * 删除一条信息
     */
    public Ret deleteByMsg(int nid) {
        Db.update("delete from bbs_information where nid=?", nid);
        return Ret.ok();
    }
}